import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

public class Logger {
    public final FileHandler log;
    HashMap<Date, Query> journal;

    public Logger(String path) {
        log = new FileHandler(path);
        journal = new HashMap<Date, Query>();
    }

    public void write(Query query) throws IOException {
        journal.put(Calendar.getInstance().getTime(), query);
        String date=new java.text.SimpleDateFormat("dd.MM.yy HH:mm:ss").format(java.util.Calendar.getInstance ().getTime());
        switch (query.getQueryType()) {
            case PUT:
                log.write(date + " put " + query.getQueryParameters()[0] + " " + query.getQueryParameters()[1]);
                break;
            case REMOVE:
                log.write(date + " remove " + query.getQueryParameters()[0]);
                break;
            case UPDATE:
                log.write(date + " update " + query.getQueryParameters()[0] + " " + query.getQueryParameters()[1]);
                break;
            default:
        }
    }
}
